#include "connection.hpp"

int main()
{
    // 1.实例化异步工作线程对象
    AsyncWorker::ptr worker = make_shared<AsyncWorker>();
    // 2.实例化连接对象
    Connection::ptr conn = make_shared<Connection>("127.0.0.1", 8080, worker);
    conn->connect();
    // // 3.创建信道
    mq::Channel::ptr channel = conn->openChannel();
    if (channel.get() == nullptr)
    {
        DLOG("打开信道失败");
        return 0;
    }
    else
        DLOG("打开信道成功:cid %s", channel->get_cid().c_str());

    // 4.通过信道完成：
    //      1.声明交换机exchange1（广播），队列queue1和queue2
    Map map;
    // channel->declareExchange("exchange1", FANOUT, true, true, map);
    // channel->declareMsgQueue("queue1", false, true, true, map);
    // channel->declareMsgQueue("queue2", false, true, true, map);
    //  2.绑定ex1和q1，bingkey = queue1
    // channel->Bind("exchange1", "queue1", "queue1");
    //  3.绑定ex1和q2，bingkey = new.music.#
    // channel->Bind("exchange1", "queue2", "new.music.#");
    //  4.发布消息
    for (int i = 1; i <= 20; i++)
    {
        BasicProperties bp;
        bp.set_id(UUIDHelper::uuid());
        bp.set_delivery_mode(DURABLE);
        if (i % 3 == 0)
            bp.set_routing_key("a.c");
        else if (i % 3 == 1)
            bp.set_routing_key("a.b.c.d");
        else
            bp.set_routing_key("a.c");
        channel->basicPublish("exchange1", &bp, "hello world[" + to_string(i) + "]");
    }

    // 5.关闭信道
    conn->closeChannel(channel);
    // 6.关闭连接
    return 0;
}
